package org.apmap.servlets;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.apmap.base.Flat;
import org.apmap.base.Main;
import org.apmap.forms.FlatForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteFlatAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
        FlatForm form = (FlatForm) actionForm;

        Session session = Main.getSession();
        session.beginTransaction();

        Flat flat = (Flat) session.load(Flat.class, form.getFlatid());
        session.delete(flat);

        session.getTransaction().commit();
        session.close();

        request.setAttribute("message", "Объект удален.");
        return mapping.findForward("propertiesmessage");
    }

}